<?php 

session_start();
include_once("../includes/mod_globals.inc.php");
include_once("../includes/mod_function.inc.php");
global $TOP_CONTENT_CATEGORY_SID,$TOP_AREA_CATEGORY_SID,$VERIFY_MOTHER_IMAGE_PATH,$VERIFY_MOTHER_IMAGE_NAME ;
$DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];
$_DEBUG = false;

$puri = $_REQUEST['uri'];
$pverify_site_image_path = $puri.$VERIFY_MOTHER_IMAGE_NAME;

$ptype = $_REQUEST['type'];
$pcatsid = $_REQUEST['catsid'];
$paction = $_REQUEST['action'];

if(!$ptype) $ptype = 'content';
if(!$paction) $paction = 'search';


if(!$pcatsid && ($paction == 'search' || $paction == 'updprofile')){
  if($ptype == 'area') $pcatsid = $TOP_AREA_CATEGORY_SID; //top area category sid
  else $pcatsid = $TOP_CONTENT_CATEGORY_SID; //top content category sid
}

require("../includes/foxydb.php");
$foxydb = new Foxydb();
$foxydb->open();
$primaryPath = $foxydb->findCategoryPrimaryPath($pcatsid);
$childCats = $foxydb->getChildCategories($pcatsid);
$currCat = $foxydb->findCategoryByCatSid($pcatsid);

$site = $foxydb->findSiteByUri($puri);
if($site){
  if(($ptype == 'content' || $ptype == 'area') && $paction == 'updcategory'){
    $updatePrimaryResult = $foxydb->updateSitePrimaryCategory($site['sid'],$ptype,$pcatsid);
  }
}else{
  $_SESSION['isWebMaster'] = false;
}

$sitePrimaryContentPath = $foxydb->findCategoryPrimaryPath($site['primarycatsid']);
$sitePrimaryAreaPath = $foxydb->findCategoryPrimaryPath($site['primaryareacatsid']);
$foxydb->close();

if($updateProfileResult) header( 'Location: updatecat.php?action=search&uri='.$puri ) ;

include("../includes/header.php");
include("../includes/searchbox.php");
include("verifyinfo.php");
?>

<?php 
  //echo "_SESSION['isWebmaster']=".$_SESSION['isWebMaster']." site=".$$site." currCat=".$currCat." puri=".$puri." pcatsid=".$pcatsid."<br>";
  if ($_SESSION['isWebMaster'] && $site && $currCat){?>
  <hr>
  <table align=center width="100%" cellpadding=0 cellspacing=0>
    <?php include("menu.php");	?>

    <tr>
      <td>
        <table align=center width="100%" cellpadding=0 cellspacing=0>
          <tr>
            <td align=left valign=top>
              <font size="+1"><b>当前位置&gt;&gt;
                <?php for ($i=count($primaryPath)-1;$i>=0;$i--) { 
                  $cat = $primaryPath[$i];
                  ?>
                <a href="updatecat.php?type=<?php echo $ptype; ?>&catsid=<?php echo $cat['sid']; ?>&uri=<?php echo $puri; ?>"><?php echo $cat['name']; ?></a>: 
                <?php } ?>
              </b></font>
            </td>
          </tr>
        </table>

        <hr>

        <form action='updatecat.php' method='GET' cellpadding=0 cellspacing=0>
          <INPUT type='hidden' name='type' value='<?php echo $ptype; ?>'/>
          <INPUT type='hidden' name='uri' value='<?php echo $puri; ?>'/>
          <table border=0>
            <?php 
            if($childCats && count($childCats) > 0){
              foreach($childCats as $cat){ 
            ?>
                <tr>
                  <td valign=top nowrap='true'><INPUT TYPE="radio" NAME="catsid" value='<?php echo $cat['sid']; ?>'><b><?php echo $cat['name']; ?></b></td>
                  <td valign=top><?php echo $cat['description']; ?></td>
                </tr>
            <?php }?>
                <input type='hidden' name='action' value='search'/>
                <tr><td align="center"><INPUT type='submit' name='submit' value='继续'></td></tr>
            <?php
            }else{
              if ($updatePrimaryResult){      
            ?>      
                <tr>
                  <td valign=top align='center' colspan='2'>
                    已成功将网址的<?php if($ptype == 'content'){?>主要内容类别<?php }else{?>主要所属地区<?php }?>设置为：<b><?php echo $currCat['name']; ?></b>
                  </td>
                </tr>      
            <?php }else {?>
                <INPUT TYPE="hidden" NAME="catsid" value='<?php echo $currCat['sid']; ?>'>
                <tr>
                  <td valign=top align='center' colspan='2'>
                    是否将网址的<?php if($ptype == 'content'){?>主要内容类别<?php }else{?>主要所属地区<?php }?>设置为：<b><?php echo $currCat['name']; ?></b>
                  </td>
                </tr>
                <tr>
                  <td valign=top align='center' colspan='2'><font color='red'>请仔细选择所属类别，修改所属类别后，网址在原来类别的积分或者排名将重新计算</font></td>
                </tr>
                <input type='hidden' name='action' value='updcategory'/>
                <tr><td align="center"><INPUT type='submit' name='submit' value='确定'></td></tr>      
            <?php }
            } 
            ?>      

            <tr><td>&nbsp;</td></tr>
            <tr><td>原来设置的主要内容类别&gt;&gt;
              <?php 
                for ($i=count($sitePrimaryContentPath)-1;$i>=0;$i--) { 
                  $cat = $sitePrimaryContentPath[$i];
                ?>
                  <a href="updatecat.php?type=<?php echo $ptype; ?>&catsid=<?php echo $cat['sid']; ?>&uri=<?php echo $puri; ?>"><?php echo $cat['name']; ?></a>: 
              <?php } ?>
            </td></tr>
            <tr><td>原来设置的主要所属地区&gt;&gt;
              <?php 
                for ($i=count($sitePrimaryAreaPath)-1;$i>=0;$i--) { 
                  $cat = $sitePrimaryAreaPath[$i];
                ?>
                  <a href="updatecat.php?type=<?php echo $ptype; ?>&catsid=<?php echo $cat['sid']; ?>&uri=<?php echo $puri; ?>"><?php echo $cat['name']; ?></a>: 
              <?php } ?>
            </td></tr>


          </table>
        </form>

      </td>
    </tr>


</table>
<?php }else if (!$site){
?>
  <table align=center width="100%" cellpadding=0 cellspacing=0>
    <tr>
      <td valign=middle align=center>
        没有找到网址[<A href='<?php echo $puri;?>' target='_blank'><?php echo $puri;?>]</A>,<br>请<A href='registersite.php?uri=<?php echo $puri;?>'>登陆网址</A>
      </td>
    </tr>
  </table>
<?php
  }
?>

<?php include("../includes/footer.php");?>